Core Java Interview Questions and Answers
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
Ques 296. What is Dictionary Class in Java?
Dictionary is an abstract class that represents a key/value storage repository and operates much like Map.
Given a key and value, you can store the value in a Dictionary object. Once the value is stored, you can retrieve it by using its key. Thus, like a map, a dictionary can be thought of as a list of key/value pairs.
The Dictionary class is obsolete. You should implement the Map interface to obtain key/value storage functionality.
Ques 297. What is Reference Handler Thread in Java?
- I suspect it handles running finalizers for the JVM. It's an implementation detail and as such not specified in the JVM spec.
- This only means that the java.lang.ref.Reference$Lock was locked in the method mentioned in the line preceding it (i.e in ReferenceHandler.run().
- "Native Method" simply means that the method is implemented in native (i.e. non-Java) code (think JNI).
- Unknown Source only means that the .class file doesn't contain any source code location information (at least for this specific point). This can happen either when the method is a synthetic one (doesn't look like it here), or the class was compiled without debug information.
- When a thread waits on some object, then it must have locked that object at some point down the call trace, so you can't really have a waiting on without a corresponding locked.
Ques 298. What is Main thread in Java?
3191 // Attach the main thread to this os thread 3192 JavaThread* main_thread = new JavaThread(); 3193 main_thread->set_thread_state(_thread_in_vm); 3194 // must do this before set_active_handles and initialize_thread_local_storage 3195 // Note: on solaris initialize_thread_local_storage() will (indirectly) 3196 // change the stack size recorded here to one based on the java thread 3197 // stacksize. This adjusted size is what is used to figure the placement 3198 // of the guard pages. 3199 main_thread->record_stack_base_and_size(); 3200 main_thread->initialize_thread_local_storage();
3335 // Initialize java_lang.System (needed before creating the thread) 3336 if (InitializeJavaLangSystem) { 3337 initialize_class(vmSymbols::java_lang_System(), CHECK_0); 3338 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK_0); 3339 Handle thread_group = create_initial_thread_group(CHECK_0); 3340 Universe::set_main_thread_group(thread_group()); 3341 initialize_class(vmSymbols::java_lang_Thread(), CHECK_0); 3342 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK_0); 3343 main_thread->set_threadObj(thread_object); 3344 // Set thread status to running since main thread has 3345 // been started and running. 3346 java_lang_Thread::set_thread_status(thread_object, 3347 java_lang_Thread::RUNNABLE);
967 // Creates the initial Thread 968 static oop create_initial_thread(Handle thread_group, JavaThread* thread, TRAPS) { 969 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_ NULL); 970 instanceKlassHandle klass (THREAD, k); 971 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL); 972 973 java_lang_Thread::set_thread(thread_oop(), thread); 974 java_lang_Thread::set_priority(thread_oop(), NormPriority); 975 thread->set_threadObj(thread_oop()); 976 977 Handle string = java_lang_String::create_from_str("main", CHECK_NULL); 978 979 JavaValue result(T_VOID); 980 JavaCalls::call_special(&result, thread_oop, 981 klass, 982 vmSymbols::object_initializer_name(), 983 vmSymbols::threadgroup_string_void_signature(), 984 thread_group, 985 string, 986 CHECK_NULL); 987 return thread_oop(); 988 }
Ques 299. What is Signal Dispatcher thread in Java?
Signal Dispatcher is a thread that handles the native signals sent by the OS to your JVM.
Ques 300. What is multithreading in Java?
Java is a multithreaded programming language which means we can develop multithreaded program using Java. A multithreaded program contains two or more parts that can run concurrently and each part can handle different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.
By definition multitasking is when multiple processes share common processing resources such as a CPU. Multithreading extends the idea of multitasking into applications where you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing time not only among different applications, but also among each thread within an application.
Multithreading enables you to write in a way where multiple activities can proceed concurrently in the same program.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
Most helpful rated by users:
- How could Java classes direct program messages to the system console, but error messages, say to a file?
- What are the differences between an interface and an abstract class?
- Why would you use a synchronized block vs. synchronized method?
- How can you force garbage collection?
- What are the differences between the methods sleep() and wait()?